package com.as.client.charts;


import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.IntegerFieldDef;
import com.gwtext.client.data.MemoryProxy;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.chart.yui.LineChart;
import com.gwtext.client.widgets.chart.yui.SeriesDefY;
import com.gwtext.client.widgets.grid.ColumnConfig;
import com.gwtext.client.widgets.grid.ColumnModel;
import com.gwtext.client.widgets.grid.EditorGridPanel;
import com.gwtext.client.widgets.layout.HorizontalLayout;

public class GraphImpl {

	Panel panel = new Panel(); 
	public GraphImpl(){
		 
		panel.setPaddings(15);     
       panel.setLayout(new HorizontalLayout(15));
       
       MemoryProxy proxy = new MemoryProxy(getData());  
       RecordDef recordDef = new RecordDef(  
    		   new FieldDef[]{  
    				   new StringFieldDef("time"),  
    				   new IntegerFieldDef("dif")  
    				   
     	               }  
       	        ); 
       
       ArrayReader reader = new ArrayReader(recordDef);  
                final Store store = new Store(proxy, reader);  
                store.load();
                
             
                     SeriesDefY[] seriesDef = new SeriesDefY[]{  
                 
                               new SeriesDefY("dif", "dif")  
                                
                   
                        }; 
 
                   
                     
                     final LineChart chart = new LineChart();  
                            chart.setTitle("Cotization fluctuation");  
                            chart.setWMode("transparent");  
                              chart.setStore(store);  
                              chart.setSeries(seriesDef);  
                              chart.setXField("time"); 
//                              chart.setDataTipFunction("getDataTipText");  
                              chart.setExpressInstall("js/yui/assets/expressinstall.swf");  
                              chart.setWidth(500);  
                              chart.setHeight(400);
//                              chart.setAutoHeight(true);
//                              chart.setAutoWidth(true);
                              chart.setAutoScroll(true);
                              chart.setVisible(true);
                             
                        
                              panel.add(chart);  
                              panel.setVisible(true);
                              panel.setAutoWidth(true);
                              panel.setAutoHeight(true);
                              panel.setAutoScroll(true);
//                              panel.setSize("400", "300");
                              
                              ColumnConfig hourConfig = new ColumnConfig("time", "time", 140, true);
                              ColumnConfig difConfig = new ColumnConfig("dif", "dif", 140, true);
                              
                              ColumnModel columnModel = new ColumnModel(new ColumnConfig[]{  
                            		                 hourConfig,  
                            		                 difConfig,  
                            		                  
                            		          }); 
                              
                              EditorGridPanel grid = new EditorGridPanel();  
                                      grid.setStore(store);  
                                      grid.setColumnModel(columnModel);  
                                      grid.setWidth(300);
                                      grid.setHeight(450);
                                      grid.setAutoScroll(true);
                                      panel.add(grid);
                                      panel.setVisible(true);
 
	}
	
 private static Object[][] getData() {  
       return new Object[][]{  
	             new Object[]{"00:20:34", 500},  
		          new Object[]{"18:17:59", 1000},  
		          new Object[]{"20:25:36",650},  
		          new Object[]{"19:12:34",1200},  
		          new Object[]{"10:48:09", 400},  
		          new Object[]{"12:49:07", 2000},
	             new Object[]{"19:29:07", 1300},
	             new Object[]{"02:56:12", 350},
	             new Object[]{"14:45.56", 1400},
	             new Object[]{"16:34:45", 1200},
	             new Object[]{"15:02:12", 1500},
	             new Object[]{"17:20:07", 2000},
	             new Object[]{"18:49:07", 2000},
	             new Object[]{"23:48:07", 1200},
	             new Object[]{"04:49:07", 1400},
	             new Object[]{"03:23:07", 1200},
	             new Object[]{"21:23:07", 1100},
	             new Object[]{"03:23:07", 1200},
	             new Object[]{"13:28:07", 1500},
	             new Object[]{"16:23:07", 1400},
	             new Object[]{"05:23:07", 1800},
	             new Object[]{"09:23:07", 2200},
	             new Object[]{"16:33:07", 1460},
	             new Object[]{"15:23:34", 2800},
	             new Object[]{"19:23:17", 5200} 
	             
		         }; 
}
 
 
 
 public Panel getPanel(){
	 return panel;
 }
 
}